package com.sinosoft.cloud.access.abc.service;

import com.sinosoft.cloud.access.annotations.AccessService;
import com.sinosoft.cloud.access.entity.*;
import com.sinosoft.cloud.access.service.AccessServiceBean;
import com.sinosoft.cloud.rest.TradeInfo;
import com.sinosoft.lis.entity.*;
import com.sinosoft.utility.CErrors;
import org.apache.log4j.Logger;

import java.text.SimpleDateFormat;


/**
 * 保单详情查询
 */
@AccessService(name = "abc", transCode = "1021")
public class DetailContQuery extends AccessServiceBean {

    /*日志管理类*/
    private final Logger cLogger = Logger.getLogger(getClass());
    /*错误处理类*/
    public CErrors mErrors = new CErrors();
    /*报文体类*/
    private Body body;
    /*报文头类*/
    private Head head;

    //注入微服务接口
//	    @Autowired
//	    PolicyDetailService policyDetailService;

    //转换处理
    @Override
    public TranData service(TranData msg) {
        cLogger.info("DetailContQuery start...");

        //TranData备份到本类
        if (!getInputData(msg)) {
            msg.getHead().setFlag("1");
            msg.getHead().setDesc("报文数据异常");
            return msg;
        }

        //标准报文转TradeInfo
        TradeInfo reqTradeInfo = stdToPojo();

        //调用微服务
        TradeInfo respTradeInfo = null;
//	        respTradeInfo = policyDetailService.service(reqTradeInfo);
//	        if (null == reqTradeInfo.getErrorList())
//	        {
//	            cLogger.info("调用policyDetailService成功。返回结果是：" + respTradeInfo.toString());
//	        }else {
//	            cLogger.info("调用policyDetailService失败。" + respTradeInfo.getErrorList().toString());
//	        }

        //TradeInfo转标准报文
        msg = pojoToStd(respTradeInfo, msg);

        cLogger.info("DetailContQuery end...");
        return msg;
    }

    //TranData备份到本类
    private boolean getInputData(TranData cInputData) {

        body = cInputData.getBody();
        head = cInputData.getHead();
//	        contnoDetail= cInputData.getBody().getContnoList().getContnoDetail();
//	        riskList= cInputData.getBody().getContnoList().getContnoDetail().getRiskList();
//	        riskDetail= cInputData.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail();
//	        = cInputData.getBody().getContnoList().getContnoDetail().getBnfList();

        if (null == body) {
            cLogger.error("接收到报文中body数据异常");
            return false;
        }

        if (null == head) {
            cLogger.error("接收到报文中Head数据异常");
            return false;
        }

        return true;
    }

    //标准报文转TradeInfo
    private TradeInfo stdToPojo() {
        TradeInfo tradeInfo = new TradeInfo();
//	        tradeInfo.addData(LCPolPojo.class.getName(),getPol());
//	        tradeInfo.addData(PolQuery.class.getName(),getPolQuery());
        //测试块------------------------------
        System.out.println(body.getContNo() + "--------------------------------哈哈--------------------------------------------------");
        System.out.println(body.getRiskCode() + "-------------------------------哈哈---------------------------------------------------");
        System.out.println(head.getTranDate() + "-------------------------------哈哈---------------------------------------------------");
        //----------------------------------
        return tradeInfo;
    }

    //TradeInfo转标准报文
    public TranData pojoToStd(TradeInfo respTradeInfo, TranData msg) {
        //微服务返回的数据
        LCContPojo responseLCCont = (LCContPojo) respTradeInfo.getData(LCContPojo.class.getName());
        LCPolPojo responseLCPol = (LCPolPojo) respTradeInfo.getData(LCPolPojo.class.getName());
        LMRiskPojo responseLMRisk = (LMRiskPojo) respTradeInfo.getData(LMRiskPojo.class.getName());
        LCAppntPojo responseLCAppnt = (LCAppntPojo) respTradeInfo.getData(LCAppntPojo.class.getName());
        LCAddressPojo responseLCAddress = (LCAddressPojo) respTradeInfo.getData(LCAddressPojo.class.getName());
        LCCustomerImpartParamsPojo responseLCCustomerImpartParams = (LCCustomerImpartParamsPojo) respTradeInfo.getData(LCCustomerImpartParamsPojo.class.getName());
//	    	PolQuery responsePolQuery = (PolQuery) respTradeInfo.getData(PolQuery.class.getName());


        //封装数据到trandata
        msg.getHead().setFlag("0");
//	    	trandata用到的对象
        msg.getBody().setContnoList(new ContnoList());
        msg.getBody().getContnoList().setContnoDetail(new ContnoDetail());
        msg.getBody().getContnoList().getContnoDetail().setRiskList(new RiskList());
        msg.getBody().getContnoList().getContnoDetail().getRiskList().setRiskDetail(new RiskDetail());
        msg.getBody().getContnoList().getContnoDetail().setBnfList(new BnfList());
        //开始封装
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//	        msg.getBody().getContnoList().getContnoDetail().setContNo(responseLCCont.getContNo());
//	        msg.getBody().getContnoList().getContnoDetail().setProposalPrtNo(responseLCCont.getPrtNo());
//	        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setRiskCode(responseLMRisk.getRiskCode());
//	        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setRiskName(responseLMRisk.getRiskName());;
//	        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setAppflag(responsePolQuery.getPolicyStatus());;
//	        msg.getBody().getContnoList().getContnoDetail().setPolicyPledge(responsePolQuery.getPolicyPledge());
//	        msg.getBody().getContnoList().getContnoDetail().setAcceptDate(sdf.format(responseLCCont.getPolApplyDate()));
//	        msg.getBody().getContnoList().getContnoDetail().setPolicyBgnDate(sdf.format(responseLCCont.getPolApplyDate()));
//	        msg.getBody().getContnoList().getContnoDetail().setPolicyEndDate(sdf.format(responseLCPol.getEndDate()));
//	        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setMult(String.valueOf((long)(responseLCPol.getMult())));
//	        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setPrem(String.valueOf((long)(responseLCPol.getPrem())));
//	        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setAmnt(String.valueOf((long)(responseLCPol.getAmnt())));
//	        msg.getBody().getContnoList().getContnoDetail().setPolicyValue(String.valueOf((long)(responsePolQuery.getPolicyValue())));
//	        msg.getBody().getContnoList().getContnoDetail().setAccountValue("");
//	        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setInsuYear(String.valueOf(responseLCPol.getInsuYear()));
//	        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setPayIntv(String.valueOf(responseLCPol.getPayIntv()));
//	        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setPayEndYear("");
//	        msg.getBody().setAppntBankAccNo(responseLCCont.getNewBankAccNo());
//	        msg.getBody().setAppntIDType(responseLCAppnt.getIDType());
//	        msg.getBody().setAppntIDNo(responseLCAppnt.getIDNo());
//	        msg.getBody().setAppntName(responseLCAppnt.getAppntName());
//	        msg.getBody().setAppntSex(responseLCAppnt.getAppntSex());
//	        msg.getBody().setAppntBirthday(String.valueOf(responseLCAppnt.getAppntBirthday()));
//	        msg.getBody().setAppntPostalAddress(responseLCAddress.getHomeAddress());
//	        msg.getBody().setAppntZipCode(responseLCAddress.getHomeZipCode());
//	        msg.getBody().setAppntEmail(responseLCAddress.getEMail());
//	        msg.getBody().setAppntPhone(responseLCAddress.getPhone());
//	        msg.getBody().setAppntMobile(responseLCAddress.getMobile());
//	        msg.getBody().setAppntMSalary(responseLCCustomerImpartParams.getImpartParam());
//	        msg.getBody().getContnoList().getContnoDetail().setRelationToAppnt(responseLCAppnt.getRelatToInsu());
//	        msg.getBody().getContnoList().getContnoDetail().setInsuredName(responseLCCont.getInsuredName());
//	        msg.getBody().getContnoList().getContnoDetail().setInsuredSex(responseLCCont.getInsuredSex());
//	        msg.getBody().getContnoList().getContnoDetail().setInsuredIDType(responseLCCont.getInsuredIDType());
//	        msg.getBody().getContnoList().getContnoDetail().setInsuredIDNo(responseLCCont.getInsuredIDNo());
//	        msg.getBody().getContnoList().getContnoDetail().setInsuredBirthday(String.valueOf(responseLCCont.getInsuredBirthday()));
        msg.getBody().getContnoList().getContnoDetail().setBnfNum("");
        msg.getBody().getContnoList().getContnoDetail().getBnfList().setBnfDetail("");
        //测试块---------------------------------------------
        //封装数据到trandata
        msg.getHead().setFlag("0");

        msg.getBody().setContnoList(new ContnoList());
        msg.getBody().getContnoList().setContnoDetail(new ContnoDetail());
        msg.getBody().getContnoList().getContnoDetail().setRiskList(new RiskList());
        msg.getBody().getContnoList().getContnoDetail().getRiskList().setRiskDetail(new RiskDetail());
        msg.getBody().getContnoList().getContnoDetail().setBnfList(new BnfList());

        msg.getBody().getContnoList().getContnoDetail().setProposalPrtNo("呵呵");
        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setRiskCode("呵呵");
        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setRiskName("呵呵");
        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setAppflag("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setPolicyPledge("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setAcceptDate("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setPolicyBgnDate("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setPolicyEndDate("呵呵");
        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setMult(String.valueOf((long) (1000.00)));
        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setPrem(String.valueOf((long) (1000.00)));
        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setAmnt(String.valueOf((long) (2000.00)));
        msg.getBody().getContnoList().getContnoDetail().setPolicyValue("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setAccountValue("呵呵");
        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setInsuYear("呵呵");
        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setPayIntv("呵呵");
        msg.getBody().getContnoList().getContnoDetail().getRiskList().getRiskDetail().setPayEndYear("呵呵");
        msg.getBody().setAppntBankAccNo("呵呵");
        msg.getBody().setAppntIDType("呵呵");
        msg.getBody().setAppntIDNo("呵呵");
        msg.getBody().setAppntName("呵呵");
        msg.getBody().setAppntSex("呵呵");
        msg.getBody().setAppntBirthday("1992-09-12");
        msg.getBody().setAppntPostalAddress("呵呵");
        msg.getBody().setAppntZipCode("呵呵");
        msg.getBody().setAppntEmail("呵呵");
        msg.getBody().setAppntPhone("呵呵");
        msg.getBody().setAppntMobile("呵呵");
        msg.getBody().setAppntMSalary("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setRelationToAppnt("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setInsuredName("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setInsuredSex("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setInsuredIDType("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setInsuredIDNo("呵呵");
        msg.getBody().getContnoList().getContnoDetail().setInsuredBirthday("1992-08-04");
        msg.getBody().getContnoList().getContnoDetail().setBnfNum("呵呵");
        msg.getBody().getContnoList().getContnoDetail().getBnfList().setBnfDetail("呵呵");

        //---------------------------------------------
        return msg;
    }

    @Override
    public TradeInfo service(TradeInfo msg) {
        return null;
    }


//	    //封装LCPolPojo给微服务
//	    public ArrayList<LCPolPojo> getPol(){
//	    	ArrayList<LCPolPojo> lcPolPojoList = new ArrayList<>();
//	    	LCPolPojo rLcPolPojo = new LCPolPojo();
//	    	rLcPolPojo.setContNo(body.getContNo());
//	    	rLcPolPojo.setRiskCode(body.getRiskCode());
//	    	lcPolPojoList.add(rLcPolPojo);
//	    	return lcPolPojoList;
//	    }
//	    //封装PolQuery给微服务
//	    public PolQuery getPolQuery(){
//	    	PolQuery polQuery = new PolQuery();
//	    	polQuery.setTransDate(head.getTranDate());
//	    	return polQuery;
//	    }


}
